package com.example.mes_boot.controller;

import com.example.mes_boot.pojo.checkpoint;
import com.example.mes_boot.pojo.factory;
import com.example.mes_boot.pojo.process;
import com.example.mes_boot.service.Indexservice;
import com.example.mes_boot.service.imp.addservieimpl;
import com.example.mes_boot.service.imp.deleservieimpl;
import com.example.mes_boot.service.imp.updataservieimpl;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/process")
public class processcontroller {
    @Autowired
    private Indexservice indexservice;
    @Autowired
    private com.example.mes_boot.service.imp.deleservieimpl deleservieimpl;
    @Autowired
    private com.example.mes_boot.service.imp.addservieimpl addservieimpl;
    @Autowired
    private com.example.mes_boot.service.imp.updataservieimpl updataservieimpl;
    //初始接口
    @PostMapping("/load")
    private List<process> find(){ return indexservice.findByprocess(null); }
    //分页接口
    @PostMapping("/page")
    private List<process> findby(@RequestBody process point) {
        int currPage=point.getPage();//当前页码
        int pageSize=8;//当前页显示记录数量
        //注意：currPage和start别搞错了，一个表示当前页码，一个是从第几行读取记录
        int start = (currPage-1)*pageSize;//计算从第几行读取记录
        RowBounds rowBounds = new RowBounds(start,pageSize);
        return indexservice.findByprocesspage(rowBounds);
    }
    @PostMapping("/dele")
    private void dele(@RequestBody process oid ){
        deleservieimpl.deleprocess(oid.getId());
    }
    //修改接口
    @PostMapping("/updata")
    private void   updata(@RequestBody process id){
        updataservieimpl.updataprocess(id);
        updataservieimpl.updatamaterial(id.getMaterial_id(),id.getName());
    }
    //模糊查询
    @PostMapping("/sele")
    private  List<process> sele(@RequestBody process sele){
        return indexservice.findByprocess(sele.getName());
    }
    @PostMapping("/add                                                                                                                                      ")
    private void addapi(@RequestBody process id){
        addservieimpl.addprocess(id);
    }
}
